setwd("mcss_prep/")

rm(list = ls())

source("./functions/fun.R")

library(reshape)
library(foreign)
library(xtable)
library(stringr)
library(plyr)
library(rjags)

# Generate the data from the datasource folder. 
source("data_chesprior_east.R")
source("data_ceeprior.R")
source("data_cmpempdata_all_east2.R")

# Reshape the data for JAGS. 
# m300
source("./models/m300/data.R")
source("./models/m301/data.R")

# Estimate each model with JAGS.
source("./models/m300/estimation.R")
source("./models/m301/estimation.R")

# Run diagnostics on the model output. 
dodiags("/m300/out_jags")
dodiags("/m301/out_jags")

# Get phi's mean / BCI from each model. 
doresults("m300")
load("./models/m300/meanbci_phi.Rdata")
write.csv(phisum, file="./models/m300/phisum300.csv")

doresults("m301")
load("./models/m301/meanbci_phi.Rdata")
write.csv(phisum, file="./models/m301/phisum301.csv")